package src.main.kotlin.day91

/**
 * 5.可变参数
 *  vararg
 *
 */

fun main() {
    val box:MagicBox5<Boy> = MagicBox5(
        Boy("jack", 18),
        Boy("marry", 19),
        Boy("jerry", 15),

        )

    box.available = true
    box.fetch5(1)?.run {
        println("you find a $name")
    }


}

//可变参数
class MagicBox5<T : Human5>(vararg item:T){
    var available = false
    private var subject5:Array<out T> = item
    fun fetch5(index:Int): T?{
        return subject5[index].takeIf { available  }
    }


}

open class Human5(val age:Int)
class Boy(val name: String, age:Int):Human5(age)

